(function ($) {
    $.fn.extend({
        //登录后效果
        login() {
            let userStr = JSON.parse(localStorage.getItem("user")) || "[]";
            if (userStr == "[]") {
                return;
            } else {
                $(".notLogin").find("span").html("购物车空空的哦~,去看看心仪的商品吧~~");
                $(".notLogin").find("span").css("marginTop","34px")
                $(".notLogin").find("a").hide();
                $(".uname").html(userStr.u_name);
                $(".uname").attr("href", "");
                $(".break").html("退出");
                if ($(".break").html() == "退出") {
                    $(".break").attr("href", "");
                    $(".break").on("click", function () {
                        localStorage.clear("user");
                    })
                }
                $(".hide").hide();
            }
        },
        //购物车效果
        hovershow(ele) {
            this.on("mouseenter", function () {
                $(ele).show()
                $(".shoppingbag").css({
                    "height": "38px",
                    "borderBottom": 0
                })
            }).on("mouseleave", function () {
                $(ele).hide()
                $(".shoppingbag").css({
                    "height": "34px",
                    "borderBottom": " 1px solid #ccc"
                })
            })
        },
        //menulist效果
        shadowshow() {
            this.find(".menu-Col-li").on("mouseenter", function () {
                $(this).addClass("menu-Col-lishow").siblings().removeClass("menu-Col-lishow");
                let index = $(this).index();
                $(".showBoxAll").children().eq(index).show().siblings().hide().on("mouseleave", function () {
                    let index = $(this).index();
                    $(".showBoxAll").children().hide();
                    $(".menu-Col-li").removeClass("menu-Col-lishow");
                });
            })
        },
        //轮播图效果
        seamless() {
            let imgIndex = 0;
            let pointIndex = 0;
            let timer = 0;
            let self = this;
            for (let i = 0; i < this.find(".bannerList>li").length; i++) {
                $(`<span class=${i == 0 ? 'active' : ''}></span > `).appendTo(this.find(".point"))
            }
            //自动轮播
            const autoPlay = () => {
                imgIndex++;
                if (imgIndex == self.find(".bannerList>li").length) {
                    imgIndex = 0;
                }
                self.find(".bannerList>li").eq(imgIndex).addClass("show").siblings().removeClass("show");

                pointIndex++;
                if (pointIndex == self.find(".bannerList>li").length) {
                    pointIndex = 0;
                }
                this.find(".point>span").eq(pointIndex).addClass("active").siblings().removeClass('active')
            }
            timer = setInterval(autoPlay, 1500);
            //鼠标移入,暂停
            this.on("mouseenter", function () {
                clearInterval(timer)
            })
            this.on("mouseleave", function () {
                timer = setInterval(autoPlay, 1500);
            })
            //事件委托,给动态的下标,绑定点击事件
            this.on("click", ".point>span", function () {
                imgIndex = pointIndex = $(this).index() - 1;
                autoPlay()
            })
            //给箭头绑定点击事件
            this.on("click", ".left-arrow", function () {
                imgIndex--;
                pointIndex--;
                if (imgIndex < 0) {
                    imgIndex = pointIndex = self.find(".bannerList>li").length - 1;
                }
                self.find(".bannerList>li").eq(imgIndex).addClass("show").siblings().removeClass("show");
                self.find(".point>span").eq(pointIndex).addClass("active").siblings().removeClass('active')
            })
            this.on("click", ".right-arrow", function () {
                imgIndex++;
                pointIndex++;
                if (imgIndex > self.find(".bannerList>li").length - 1) {
                    imgIndex = pointIndex = 0;
                }
                self.find(".bannerList>li").eq(imgIndex).addClass("show").siblings().removeClass("show");
                self.find(".point>span").eq(pointIndex).addClass("active").siblings().removeClass('active')
            })
        }
    })
})(jQuery)
$(function () {
    $(".bag").hovershow(".shopshow");
    $(".content-menu-Col").shadowshow();
    $(".banner").seamless();
    $(".carousel-left").seamless();
    $(".h-content").login();
})
